<?php
App::uses('AppModel', 'Model');
/**
 * User Model
 *
 * @property Role $Role
 */
class User extends AppModel {

/**
 * Primary key field
 *
 * @var string
 */
	public $primaryKey = 'user_id';

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'username';


	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Role' => array(
			'className' => 'Role',
			'foreignKey' => 'role_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
        
        public function beforeSave($options = array()) {
            parent::beforeSave($options);
            if(isset($this->data[$this->alias]['password'])){
                $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);            
            }
            return true;
        }
        
        var $actsAs = array('Acl' => array('requester'));
 
    function parentNode() {
        if (!$this->id && empty($this->data)) {
            return null;
        }
        $data = $this->data;
        if (empty($this->data)) {
            $data = $this->read();
        }
        if (!$data['User']['role_id']) {
            return null;
        } else {
            return array('Role' => array('role_id' => $data['User']['role_id']));
        }
    }
    
    
}
